package com.hxzy.common.util;

import cn.hutool.json.JSONUtil;
import com.hxzy.common.enums.AckCode;
import com.hxzy.common.resp.R;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author wy
 * @Description TODO
 * @Date 2023/8/29 17:02
 * @Version 1.0
 */
public class ServletUtil {

    public static void outJson(HttpServletResponse response, AckCode ackCode) throws IOException {
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json");

        PrintWriter out= response.getWriter();

        R r=R.build(ackCode);
        //json序列化
        String jsonStr= JSONUtil.toJsonStr(r);

        out.println(jsonStr);
        out.flush();
        out.close();
    }
}
